package com.winchain.chainbill.bill.biz.send.cmd;

import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICommand;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbSnd;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.send.service.BillArQuotaService;
import com.winchain.chainbill.bill.biz.send.service.BillCrQuotaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillQuotaCmd implements ICommand<Bill<CbSnd>> {
	@Autowired
	private BillArQuotaService billArQuotaService;
	@Autowired
	private BillCrQuotaService billCrQuotaService;

	public boolean execute(CommandContext<Bill<CbSnd>> context) throws Exception {
		CbRec bill = ((Bill) context.getSource()).getRec();
		CbSnd send = (CbSnd) ((Bill) context.getSource()).getSource();

		String billType = bill.getBillType();
		if ("0".equals(billType)) {
			this.billArQuotaService.unblock(bill, send);
		} else {
			this.billCrQuotaService.unblock(bill, send);
		}
		return false;
	}
}
